const noop = () => {
};

module.exports = function (redisClient, module) {
    module.flushdb = (callback = noop) => redisClient.send_command('flushdb', [], callback);

    module.emptydb = (callback) => module.flushdb(callback);

    module.exists = (key, callback) => redisClient.exists(key, (err, exists) => {
        callback(err, exists === 1);
    });

    module.delete = (key, callback = noop) => redisClient.del(key, callback);

    module.deleteAll = (keys, callback = noop) => {
        const multi = redisClient.multi();
        for (let i = 0; i < keys.length; i += 1) {
            multi.del(keys[i]);
        }
        multi.exec(callback);
    };

    module.get = (key, callback) => redisClient.get(key, callback);

    module.set = (key, value, callback = noop) => redisClient.set(key, value, callback);

    module.increment = (key, callback = noop) => redisClient.incr(key, callback);

    module.rename = (oldKey, newKey, callback = noop) => redisClient.rename(oldKey, newKey, (err) => {
        callback(err && err.message !== 'ERR no such key' ? err : null);
    });

    module.expire = (key, seconds, callback = noop) => redisClient.expire(key, seconds, callback);

    module.expireAt = (key, timestamp, callback = noop) => redisClient.expireat(key, timestamp, callback);

    module.pexpire = (key, ms, callback = noop) => redisClient.pexpire(key, ms, callback);

    module.pexpireAt = (key, timestamp, callback = noop) => redisClient.pexpireat(key, timestamp, callback);
};
